package com.uziot.activiti6.common.util;

import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author shidt
 * @version V1.0
 * @className Result
 * @date 2021-02-26 10:38:41
 * @description
 */

public class Result extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public Result() {
        this.put("code", ResponseCode.SUCCESS.getCode());
        this.put("msg", ResponseCode.SUCCESS.getMsg());
    }

    public Result(ResponseCode response) {
        this.put("code", response.getCode());
        this.put("msg", response.getMsg());
    }

    public static Result error() {
        return error(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getMsg());
    }

    public static Result error(String msg) {
        return error(ResponseCode.FAIL.getCode(), msg);
    }

    public static Result error(HttpStatus code, String msg) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    public static Result ok(Map<String, Object> map) {
        Result result = new Result();
        result.putAll(map);
        return result;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}